package servlet;

import model.classes;
import model.teacher;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/addClassInfo")
public class addClassInfo extends HttpServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        int cno=0;

        if(req.getParameter("cno")!="" && req.getParameter("cno")!=null){
           cno=Integer.parseInt(req.getParameter("cno"));
        }

        String cname=req.getParameter("cname");

        String tname=req.getParameter("tname");

        String taccount=req.getParameter("taccount");

        if(cno!=0 && cname!=null&& tname!=null && taccount!=null){
            if (classes.addClassInfo(cno,cname) && teacher.addTeacherInfo(taccount,cno)){
                req.setAttribute("addClassInfo","添加成功");
                req.getRequestDispatcher("/jsp/a_addClassInfo.jsp").forward(req,resp);
            }else{
                req.setAttribute("addClassInfo","添加失败");
                req.getRequestDispatcher("/jsp/a_addClassInfo.jsp").forward(req,resp);
            }
        }
        else{
            req.setAttribute("addClassInfo","请填写完整信息");
            req.getRequestDispatcher("/jsp/a_addClassInfo.jsp").forward(req,resp);
        }




    }
}
